import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import viteCompression from 'vite-plugin-compression'
import AutoImport from "unplugin-auto-import/vite"
import postCssPxToRem from "postcss-pxtorem"

export default defineConfig({
  // 配置相对路径
  base: './',
  plugins: [
    vue(),
    // 执行gzip压缩,代码打包的更小
    viteCompression(),
    AutoImport({
      imports: ["vue", "vue-router", "pinia"], //自动引入vue的ref、toRefs、onmounted等，无需在页面中再次引入
    })
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    },
  },
  build: {
    //这里一定要加minify:'terser',否则下面的不起作用
    minify: 'terser',
    terserOptions: {
      compress: {
        //生产环境时移除console.log
        drop_console: true,
        drop_debugger: true,
      }
    },
    rollupOptions: {
      output: {
        chunkFileNames: 'js/[name]-[hash].js',
        entryFileNames: 'js/[name]-[hash].js',
        assetFileNames: '[ext]/[name]-[hash].[ext]'
      }
    }
  },
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 19.2, // 1rem的大小
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
        })
      ]
    }
  },
  server: {
    host: "localhost",
    hmr: true,
    // proxy:{
    //   '/ss':{
    //     target:'',
    //     changeOrigin:true,
    //     rewrite:(path) => path.replace(/^\/ss/,'')
    //   }
    // }
  },
  define: {
    'process.env': {},
  }

})
